package org.example.udemo3.UserController;

import org.example.udemo3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

//@Controller
//public class UserController {
//    @Autowired
//    private UserService userService;
//
//    //有多个构造方法时,默认使用无参的
//    public UserController(){
//        System.out.println("无参");
//    }
//
//    @Autowired//加上注解,表示指定使用这个构造方法
//    public UserController(UserService userService) {
//        System.out.println("有参构造方法");
//    }
//
//    public void say(){
//        System.out.println("UserController.say...");
//        userService.say();
//    }
//}
@Controller
public class UserController {
    //属性注入
//    @Autowired
//    private UserService userService;

    //构造方法注入
//    private UserService userService;
//
//    private UserInfo userInfo;
//
//    public UserController() {
//        System.out.println("无参构造方法");
//    }
//
//    @Autowired
//    public UserController(UserService userService, UserInfo userInfo) {
//        System.out.println("有参构造方法");
//        this.userInfo = userInfo;
//        this.userService = userService;
//    }

    //setter方法注入
    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public void say(){
        System.out.println("UserController say...");
        userService.say();
//        System.out.println(userInfo);
    }
}